package com.keshan.controller;

import com.keshan.pojo.Message;
import com.keshan.pojo.MessageJson;
import com.keshan.utils.Msg;
import com.keshan.service.MessageServices;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @author keshan
 * @date 2022/10/21 - 19:22
 */
@CrossOrigin
@Controller
@RequestMapping("/message")
public class MessageController {
    @Autowired
    MessageServices messageServices;

    @RequestMapping("/insertmessage")
    @ResponseBody
    public Msg insertBySelectiveToMessage(@RequestBody MessageJson messageJson){
        Message message =new Message();
        message.setCommunityid(messageJson.getCommunityid());
        message.setDeviceid(messageJson.getDeviceid());
        message.setDeviceType(messageJson.getDevice_type());
        message.setName(messageJson.getName());
        message.setType(messageJson.getType());
        message.setUrl(messageJson.getUrl());
        int result = messageServices.insertBySelectiveMessage(message);
        return Msg.success().add("result",result);
    }
}
